﻿using Assets.Script.Data.EnemyData;
using Assets.Script.Data.Player;
using Assets.Script.Human.Enemy;
using Assets.Script.Human.Enemy.Enemys;
using Newtonsoft.Json;
using Script.EnemySystem.Tools;
using System;
 using System.Collections;
 using UnityEngine;
 using UnityEngine.Events;

 namespace Assets.Script.Human.Enemy
{
    /// <summary>
    ///  怪物生命周期
    /// </summary>
    [RequireComponent(typeof(Rigidbody))]
    public class EnemyBody : MonoBehaviour
    {
        public Animator Animator;

        [Header("近战属性(可null)")]
        [SerializeField] public Collider atkColider;//近战攻击体
        [SerializeField] AttackColider attackColider;


        [HideInInspector] public Rigidbody Rb { get; private set; }


        [HideInInspector] public EnemyData Data { get; set; }
        [HideInInspector] public EnemyState State { get; set; } = new EnemyState();
        public float nowHp { get; protected set; }

        private void Awake()
        {
            Rb = GetComponent<Rigidbody>();
        }

        /// <summary>
        /// 刷新属性与状态
        /// </summary>
        public void ReInit()
        {
            nowHp = Data.MaxHp;
            
            if (attackColider!=null)
            {
                attackColider.Init(this);
            }
            
        }

        public void UpdateSpaceInfo(BattleSystem.SyncModle.SpaceInfo spaceInfo)//todo 同步角度、缩放
        {
            Rb.MovePosition(spaceInfo.pos);
        }

        public void TakeDamage(float dmg, float force, Vector3 position)
        {
            nowHp -= dmg;
            if (nowHp < 0)
            {
                //Die
            }
        }


        

        public void GetHeal(float heal)
        {
            nowHp += heal;
            if (Data.MaxHp > nowHp)
            {
                nowHp = Data.MaxHp;
            }
        }

#if UNITY_EDITOR
        private void OnDrawGizmos()
        {
            Gizmos.color = Color.yellow;
            if (Data != null)
            {
                var position = transform.position;
                Gizmos.DrawWireSphere(position, Data.MeleeAttackDistance);
                Gizmos.DrawWireSphere(position, Data.RangedAttackDistance);
            }

        }
#endif



    }

    
    
}
